<?php

namespace Biz\service\SuperSubsidy;

use Biz\model\SuperSubsidy\YouZanBrandItemModel;

class YouZanBrandItem implements ConstInterface
{
    public static function getBrandUserIdByItemIds(array $itemIds)
    {
        $result = [];
        $list = YouZanBrandItemModel::selectByWhere(['item_id' => $itemIds], ['brand_user_id', 'item_id']);
        $list = $list ? array_column($list, null, 'item_id') : [];
        foreach ($itemIds as $itemId) {
            $result[$itemId] = $list[$itemId]['brand_user_id'] ?? 0;
        }
        return $result;
    }

    public function setDataValidation(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet, $cell_name, $cell_num = 1, $title, $select_str)
    {
        $sht = $spreadsheet->getActiveSheet();
        $objValidation = $sht->getDataValidation("{$cell_name}{$cell_num}");
        $objValidation->setType(PHPExcel_Cell_DataValidation::TYPE_LIST);
        $objValidation->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION);
        $objValidation->setAllowBlank(false);
        $objValidation->setShowDropDown(true);
        $objValidation->setShowInputMessage(true);
        $objValidation->setShowErrorMessage(true);
        $objValidation->setErrorTitle("输入的值有误");
        $objValidation->setError("请输入下拉框列表内的值:" . $select_str);
        $objValidation->setPromptTitle($title);
        $objValidation->setFormula1('"' . $select_str . '"');
        for ($i = $cell_num; $i <= 100; $i++) {
            $sht->setDataValidation("{$cell_name}{$i}", $objValidation);
        }
    }
}